//
//  DownloadStatus.swift
//  TestBankActor
//
//  Created by 罗万能 on 2025/6/17.
//

import Foundation
import SwiftData
@ModelActor actor BeautyModelActor {
    
    func save(){
        do{
            try self.modelContext.save()
        }catch{
            print(error)
        }
    }
    // 变更状态的函数
    func changeStatus(model: BeautyModel,to newStatus: DownloadStatus) {
        model.status = newStatus
        save()
    }
    // 变更恢复数据的函数
    func changeResumeData(model: BeautyModel, to newResumeData: Data?) {
        model.resumeData = newResumeData
    }

    func completeDownload(model: BeautyModel,with url: URL) {
        model.status = .completed
        model.localUrl = url
        model.resumeData = nil
        model.downloadedProgress = 1
        save()
        
    }
    func getResumeData(model: BeautyModel) -> Data? {
        return model.resumeData
    }
    func getStaus(model: BeautyModel) -> DownloadStatus {
        return model.status
    }
    func getRemoteUrl(model: BeautyModel) -> URL {
        return model.remoteUrl
    }
    
            
}
